<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/date_time/gregorian_calendar.ipp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/date_time</a> - gregorian_calendar.ipp<span style="font-size: 80%;"> (source / <a href="gregorian_calendar.ipp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">7</td>
            <td class="headerCovTableEntry">11</td>
            <td class="headerCovTableEntryLo">63.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* Copyright (c) 2002,2003 CrystalClear Software, Inc.</a>
<span class="lineNum">       2 </span>            :  * Use, modification and distribution is subject to the
<span class="lineNum">       3 </span>            :  * Boost Software License, Version 1.0. (See accompanying
<span class="lineNum">       4 </span>            :  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       5 </span>            :  * Author: Jeff Garland, Bart Garst
<span class="lineNum">       6 </span>            :  * $Date$
<span class="lineNum">       7 </span>            :  */
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : #ifndef NO_BOOST_DATE_TIME_INLINE
<span class="lineNum">      10 </span>            :   #undef BOOST_DATE_TIME_INLINE
<span class="lineNum">      11 </span>            :   #define BOOST_DATE_TIME_INLINE inline
<span class="lineNum">      12 </span>            : #endif
<span class="lineNum">      13 </span>            : 
<span class="lineNum">      14 </span>            : namespace boost {
<span class="lineNum">      15 </span>            : namespace date_time {
<span class="lineNum">      16 </span>            :   //! Return the day of the week (0==Sunday, 1==Monday, etc)
<span class="lineNum">      17 </span>            :   /*! Converts a year-month-day into a day of the week number
<span class="lineNum">      18 </span>            :    */
<span class="lineNum">      19 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">      20 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">      21 </span>            :   unsigned short
<span class="lineNum">      22 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::day_of_week(const ymd_type&amp; ymd) {
<span class="lineNum">      23 </span>            :     unsigned short a = static_cast&lt;unsigned short&gt;((14-ymd.month)/12);
<span class="lineNum">      24 </span>            :     unsigned short y = static_cast&lt;unsigned short&gt;(ymd.year - a);
<span class="lineNum">      25 </span>            :     unsigned short m = static_cast&lt;unsigned short&gt;(ymd.month + 12*a - 2);
<span class="lineNum">      26 </span>            :     unsigned short d = static_cast&lt;unsigned short&gt;((ymd.day + y + (y/4) - (y/100) + (y/400) + (31*m)/12) % 7);
<span class="lineNum">      27 </span>            :     //std::cout &lt;&lt; year &lt;&lt; &quot;-&quot; &lt;&lt; month &lt;&lt; &quot;-&quot; &lt;&lt; day &lt;&lt; &quot; is day: &quot; &lt;&lt; d &lt;&lt; &quot;\n&quot;;
<span class="lineNum">      28 </span>            :     return d;
<span class="lineNum">      29 </span>            :   }
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            :   //!Return the iso week number for the date
<span class="lineNum">      32 </span>            :   /*!Implements the rules associated with the iso 8601 week number.
<span class="lineNum">      33 </span>            :     Basically the rule is that Week 1 of the year is the week that contains
<span class="lineNum">      34 </span>            :     January 4th or the week that contains the first Thursday in January.
<span class="lineNum">      35 </span>            :     Reference for this algorithm is the Calendar FAQ by Claus Tondering, April 2000.
<span class="lineNum">      36 </span>            :   */
<span class="lineNum">      37 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">      38 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">      39 </span>            :   int
<span class="lineNum">      40 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::week_number(const ymd_type&amp; ymd) {
<span class="lineNum">      41 </span>            :     unsigned long julianbegin = julian_day_number(ymd_type(ymd.year,1,1));
<span class="lineNum">      42 </span>            :     unsigned long juliantoday = julian_day_number(ymd);
<span class="lineNum">      43 </span>            :     unsigned long day = (julianbegin + 3) % 7;
<span class="lineNum">      44 </span>            :     unsigned long week = (juliantoday + day - julianbegin + 4)/7;
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            :     if ((week &gt;= 1) &amp;&amp; (week &lt;= 52)) {
<span class="lineNum">      47 </span>            :       return week;
<span class="lineNum">      48 </span>            :     }
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span>            :     if (week == 53) {
<span class="lineNum">      51 </span>            :       if((day==6) ||(day == 5 &amp;&amp; is_leap_year(ymd.year))) {
<span class="lineNum">      52 </span>            :         return week; //under these circumstances week == 53.
<span class="lineNum">      53 </span>            :       } else {
<span class="lineNum">      54 </span>            :         return 1; //monday - wednesday is in week 1 of next year
<span class="lineNum">      55 </span>            :       }
<span class="lineNum">      56 </span>            :     }
<span class="lineNum">      57 </span>            :     //if the week is not in current year recalculate using the previous year as the beginning year
<span class="lineNum">      58 </span>            :     else if (week == 0) {
<span class="lineNum">      59 </span>            :       julianbegin = julian_day_number(ymd_type(static_cast&lt;unsigned short&gt;(ymd.year-1),1,1));
<span class="lineNum">      60 </span>            :       juliantoday = julian_day_number(ymd);
<span class="lineNum">      61 </span>            :       day = (julianbegin + 3) % 7;
<span class="lineNum">      62 </span>            :       week = (juliantoday + day - julianbegin + 4)/7;
<span class="lineNum">      63 </span>            :       return week;
<span class="lineNum">      64 </span>            :     }
<span class="lineNum">      65 </span>            : 
<span class="lineNum">      66 </span>            :     return week;  //not reachable -- well except if day == 5 and is_leap_year != true
<span class="lineNum">      67 </span>            : 
<span class="lineNum">      68 </span>            :   }
<span class="lineNum">      69 </span>            : 
<span class="lineNum">      70 </span>            :   //! Convert a ymd_type into a day number
<span class="lineNum">      71 </span>            :   /*! The day number is an absolute number of days since the start of count
<span class="lineNum">      72 </span>            :    */
<span class="lineNum">      73 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<a name="74"><span class="lineNum">      74 </span>            :   BOOST_DATE_TIME_INLINE</a>
<span class="lineNum">      75 </span>            :   date_int_type_
<span class="lineNum">      76 </span><span class="lineCov">    3426639 :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::day_number(const ymd_type&amp; ymd)</span>
<span class="lineNum">      77 </span>            :   {
<span class="lineNum">      78 </span><span class="lineCov">    3426639 :     unsigned short a = static_cast&lt;unsigned short&gt;((14-ymd.month)/12);</span>
<span class="lineNum">      79 </span><span class="lineCov">    3426639 :     unsigned short y = static_cast&lt;unsigned short&gt;(ymd.year + 4800 - a);</span>
<span class="lineNum">      80 </span><span class="lineCov">    3426639 :     unsigned short m = static_cast&lt;unsigned short&gt;(ymd.month + 12*a - 3);</span>
<span class="lineNum">      81 </span><span class="lineCov">    3426639 :     unsigned long  d = ymd.day + ((153*m + 2)/5) + 365*y + (y/4) - (y/100) + (y/400) - 32045;</span>
<span class="lineNum">      82 </span><span class="lineCov">    3426639 :     return d;</span>
<span class="lineNum">      83 </span>            :   }
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            :   //! Convert a year-month-day into the julian day number
<span class="lineNum">      86 </span>            :   /*! Since this implementation uses julian day internally, this is the same as the day_number.
<span class="lineNum">      87 </span>            :    */
<span class="lineNum">      88 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">      89 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">      90 </span>            :   date_int_type_
<span class="lineNum">      91 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::julian_day_number(const ymd_type&amp; ymd)
<span class="lineNum">      92 </span>            :   {
<span class="lineNum">      93 </span>            :     return day_number(ymd);
<span class="lineNum">      94 </span>            :   }
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            :   //! Convert year-month-day into a modified julian day number
<span class="lineNum">      97 </span>            :   /*! The day number is an absolute number of days.
<span class="lineNum">      98 </span>            :    *  MJD 0 thus started on 17 Nov 1858(Gregorian) at 00:00:00 UTC
<span class="lineNum">      99 </span>            :    */
<span class="lineNum">     100 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     101 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     102 </span>            :   date_int_type_
<span class="lineNum">     103 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::modjulian_day_number(const ymd_type&amp; ymd)
<span class="lineNum">     104 </span>            :   {
<span class="lineNum">     105 </span>            :     return julian_day_number(ymd)-2400001; //prerounded
<span class="lineNum">     106 </span>            :   }
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span>            :   //! Change a day number into a year-month-day
<span class="lineNum">     109 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     110 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     111 </span>            :   ymd_type_
<span class="lineNum">     112 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::from_day_number(date_int_type dayNumber)
<span class="lineNum">     113 </span>            :   {
<span class="lineNum">     114 </span>            :     date_int_type a = dayNumber + 32044;
<span class="lineNum">     115 </span>            :     date_int_type b = (4*a + 3)/146097;
<span class="lineNum">     116 </span>            :     date_int_type c = a-((146097*b)/4);
<span class="lineNum">     117 </span>            :     date_int_type d = (4*c + 3)/1461;
<span class="lineNum">     118 </span>            :     date_int_type e = c - (1461*d)/4;
<span class="lineNum">     119 </span>            :     date_int_type m = (5*e + 2)/153;
<span class="lineNum">     120 </span>            :     unsigned short day = static_cast&lt;unsigned short&gt;(e - ((153*m + 2)/5) + 1);
<span class="lineNum">     121 </span>            :     unsigned short month = static_cast&lt;unsigned short&gt;(m + 3 - 12 * (m/10));
<span class="lineNum">     122 </span>            :     year_type year = static_cast&lt;unsigned short&gt;(100*b + d - 4800 + (m/10));
<span class="lineNum">     123 </span>            :     //std::cout &lt;&lt; year &lt;&lt; &quot;-&quot; &lt;&lt; month &lt;&lt; &quot;-&quot; &lt;&lt; day &lt;&lt; &quot;\n&quot;;
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span>            :     return ymd_type(static_cast&lt;unsigned short&gt;(year),month,day);
<span class="lineNum">     126 </span>            :   }
<span class="lineNum">     127 </span>            : 
<span class="lineNum">     128 </span>            :   //! Change a day number into a year-month-day
<span class="lineNum">     129 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     130 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     131 </span>            :   ymd_type_
<span class="lineNum">     132 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::from_julian_day_number(date_int_type dayNumber)
<span class="lineNum">     133 </span>            :   {
<span class="lineNum">     134 </span>            :     date_int_type a = dayNumber + 32044;
<span class="lineNum">     135 </span>            :     date_int_type b = (4*a+3)/146097;
<span class="lineNum">     136 </span>            :     date_int_type c = a - ((146097*b)/4);
<span class="lineNum">     137 </span>            :     date_int_type d = (4*c + 3)/1461;
<span class="lineNum">     138 </span>            :     date_int_type e = c - ((1461*d)/4);
<span class="lineNum">     139 </span>            :     date_int_type m = (5*e + 2)/153;
<span class="lineNum">     140 </span>            :     unsigned short day = static_cast&lt;unsigned short&gt;(e - ((153*m + 2)/5) + 1);
<span class="lineNum">     141 </span>            :     unsigned short month = static_cast&lt;unsigned short&gt;(m + 3 - 12 * (m/10));
<span class="lineNum">     142 </span>            :     year_type year = static_cast&lt;year_type&gt;(100*b + d - 4800 + (m/10));
<span class="lineNum">     143 </span>            :     //std::cout &lt;&lt; year &lt;&lt; &quot;-&quot; &lt;&lt; month &lt;&lt; &quot;-&quot; &lt;&lt; day &lt;&lt; &quot;\n&quot;;
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            :     return ymd_type(year,month,day);
<span class="lineNum">     146 </span>            :   }
<span class="lineNum">     147 </span>            : 
<span class="lineNum">     148 </span>            :   //! Change a modified julian day number into a year-month-day
<span class="lineNum">     149 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     150 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     151 </span>            :   ymd_type_
<span class="lineNum">     152 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::from_modjulian_day_number(date_int_type dayNumber) {
<span class="lineNum">     153 </span>            :     date_int_type jd = dayNumber + 2400001; //is 2400000.5 prerounded
<span class="lineNum">     154 </span>            :     return from_julian_day_number(jd);
<span class="lineNum">     155 </span>            :   }
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span>            :   //! Determine if the provided year is a leap year
<span class="lineNum">     158 </span>            :   /*!
<span class="lineNum">     159 </span>            :    *@return true if year is a leap year, false otherwise
<span class="lineNum">     160 </span>            :    */
<span class="lineNum">     161 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     162 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     163 </span>            :   bool
<span class="lineNum">     164 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::is_leap_year(year_type year)
<span class="lineNum">     165 </span>            :   {
<span class="lineNum">     166 </span>            :     //divisible by 4, not if divisible by 100, but true if divisible by 400
<span class="lineNum">     167 </span><span class="lineNoCov">          0 :     return (!(year % 4))  &amp;&amp; ((year % 100) || (!(year % 400)));</span>
<span class="lineNum">     168 </span>            :   }
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            :   //! Calculate the last day of the month
<span class="lineNum">     171 </span>            :   /*! Find the day which is the end of the month given year and month
<span class="lineNum">     172 </span>            :    *  No error checking is performed.
<span class="lineNum">     173 </span>            :    */
<span class="lineNum">     174 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<a name="175"><span class="lineNum">     175 </span>            :   BOOST_DATE_TIME_INLINE</a>
<span class="lineNum">     176 </span>            :   unsigned short
<span class="lineNum">     177 </span><span class="lineCov">    3426639 :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::end_of_month_day(year_type year,</span>
<span class="lineNum">     178 </span>            :                                                                       month_type month)
<span class="lineNum">     179 </span>            :   {
<span class="lineNum">     180 </span>            :     switch (month) {
<span class="lineNum">     181 </span>            :     case 2:
<span class="lineNum">     182 </span><span class="lineNoCov">          0 :       if (is_leap_year(year)) {</span>
<span class="lineNum">     183 </span>            :         return 29;
<span class="lineNum">     184 </span>            :       } else {
<span class="lineNum">     185 </span><span class="lineNoCov">          0 :         return 28;</span>
<span class="lineNum">     186 </span>            :       };
<span class="lineNum">     187 </span>            :     case 4:
<span class="lineNum">     188 </span>            :     case 6:
<span class="lineNum">     189 </span>            :     case 9:
<span class="lineNum">     190 </span>            :     case 11:
<span class="lineNum">     191 </span>            :       return 30;
<span class="lineNum">     192 </span>            :     default:
<span class="lineNum">     193 </span><span class="lineNoCov">          0 :       return 31;</span>
<span class="lineNum">     194 </span>            :     };
<span class="lineNum">     195 </span>            : 
<span class="lineNum">     196 </span>            :   }
<span class="lineNum">     197 </span>            : 
<span class="lineNum">     198 </span>            :   //! Provide the ymd_type specification for the calandar start
<span class="lineNum">     199 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     200 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     201 </span>            :   ymd_type_
<span class="lineNum">     202 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::epoch()
<span class="lineNum">     203 </span>            :   {
<span class="lineNum">     204 </span>            :     return ymd_type(1400,1,1);
<span class="lineNum">     205 </span>            :   }
<span class="lineNum">     206 </span>            : 
<span class="lineNum">     207 </span>            :   //! Defines length of a week for week calculations
<span class="lineNum">     208 </span>            :   template&lt;typename ymd_type_, typename date_int_type_&gt;
<span class="lineNum">     209 </span>            :   BOOST_DATE_TIME_INLINE
<span class="lineNum">     210 </span>            :   unsigned short
<span class="lineNum">     211 </span>            :   gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::days_in_week()
<span class="lineNum">     212 </span>            :   {
<span class="lineNum">     213 </span>            :     return 7;
<span class="lineNum">     214 </span>            :   }
<span class="lineNum">     215 </span>            : 
<span class="lineNum">     216 </span>            : 
<span class="lineNum">     217 </span>            : } } //namespace gregorian
<span class="lineNum">     218 </span>            : 
<span class="lineNum">     219 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
